<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增科室信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-registerinfo-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">logo：</label>
                <div class="col-sm-8">
                    <img src="" style="width: 80px;height: 100px;display: none" id="logoImg">
                    <input type="file" class="" id="logo" accept="image/*" onchange="uploadFile()"/>
                    <input type="hidden" name="logo" id="logoVal" value="">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">科室：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">介绍：</label>
                <div class="col-sm-8">
                    <textarea name="introduce" class="form-control"></textarea>
                </div>
            </div>
<!--            <div class="form-group">-->
<!--                <label class="col-sm-3 control-label">位置：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="position" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "register/registerinfo"
        $("#form-registerinfo-add").validate({
            focusCleanup: true
        });

        function uploadFile() {
            var formData = new FormData();
            if ($('#logo')[0].files[0] == null) {
                return false;
            }
            formData.append('file', $('#logo')[0].files[0]);
            var flag = true;
            $.ajax({
                url: ctx + "common/upload",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                async: false,
                dataType: "json",
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        var data = result.fileName;
                        $("#logoVal").val(data);
                        $("#logoImg").show();
                        $("#logoImg").attr("src", data);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function (error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
            return flag;
        }

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-registerinfo-add').serialize());
            }
        }
    </script>
</body>
</html>
